package threadimpl;

/**
 * 实现Runnable接口的方式
 * 覆写run()方法
 * new Thread时，以实现类Runnable的线程为参数
 */
public class ThreadRunnable{

    public static void main(String[] args) {
        MyThread mt1 = new MyThread("线程A");
        MyThread mt2 = new MyThread("线程B");

        Thread t1 = new Thread(mt1);
        Thread t2 = new Thread(mt2);

        t1.start();
        t2.start();
    }
}


class MyThread implements Runnable{
    // 线程名称
    private String name;

    public MyThread(String name){
        this.name = name;
    }
    @Override
    public void run() {
        for(int i=0; i<10;i++){
            System.out.println(name + "运行，i = " + i);
        }
    }
}